﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Resources;

namespace _1041448_DH_Utilities
{
    public class MResources
    {
        #region ReadResourceFile
        /// <summary>
        /// method for reading a value from a resource file
        /// (.resx file)
        /// </summary>
        /// <param name="file">file to read from</param>
        /// <param name="key">key to get the value for</param>
        /// <returns>a string value</returns>
        public static string ReadResourceValue(string file, string key, out bool error)
        {
            error = false;
            //value for our return value
            string resourceValue = string.Empty;
            try
            {
                // specify your resource file name
                string resourceFile = file;
                // get the path of your file
                string filePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
                // create a resource manager for reading from
                //the resx file
                ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager(resourceFile, filePath, null);
                // retrieve the value of the specified key
                resourceValue = resourceManager.GetString(key);
            }
            catch (Exception ex)
            {
                error = true;
                resourceValue = ex.Message;
            }
            return resourceValue;
        }
        #endregion
    }
}
